<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;
use Phinx\Db\Adapter\MysqlAdapter;

final class CreateTableAdminMenu extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $table = $this->table('admin_menu', [
            'comment'   => '菜单',
            'engine'    => 'innodb',
        ]);
        $table->addColumn('pid', 'integer', [
            'comment'   => '父级, admin_menu_id',
            'default'   => 0,
            'null'      => false,
            'limit'     => 11,
            'signed'    => false
        ]);
        $table->addColumn('rank', 'integer', [
            'comment'   => '排序',
            'default'   => 0,
            'null'      => false,
            'signed'    => false,
            'limit'     => 11
        ]);
        $table->addColumn('title', 'string', [
            'comment'   => '标题',
            'null'      => false,
            'limit'     => 255
        ]);
        $table->addColumn('uri', 'string', [
            'comment'   => '链接',
            'default'   => '#',
            'null'      => true,
            'limit'     => 50
        ]);
        $table->addColumn('is_show', MysqlAdapter::PHINX_TYPE_TINY_INTEGER, [
            'comment'   => '是否在菜单中显示',
            'default'   => 1,
            'null'      => false,
            'signed'    => false,
            'limit'     => 1
        ]);
        $table->addColumn('created_at', 'datetime', ['null' => true]);
        $table->addColumn('updated_at', 'datetime', ['null' => true]);
        $table->addIndex('pid', ['name' => 'inx_pid']);
        $table->create();
    }
}
